// src/store/index.js

import { createStore } from 'vuex';

export default createStore({
    state: {
        isAuthenticated: false, // 初始状态为未登录
    },
    mutations: {
        SET_AUTHENTICATED(state, isAuthenticated) {
            state.isAuthenticated = isAuthenticated;
        },
    },
    actions: {
        login({ commit }) {
            return new Promise((resolve, reject) => {
                try {
                    // 模拟登录操作
                    commit('SET_AUTHENTICATED', true);
                    resolve();
                } catch (error) {
                    reject(error);
                }
            });
        },
        logout({ commit }) {
            commit('SET_AUTHENTICATED', false);
        },
    },
    getters: {
        isAuthenticated: state => state.isAuthenticated,
    },
});
